#!/bin/sh

. /opt/truecl/etc/clenv.sh

user=${1:-root}
h=`hostname`

r=`lha_stat 2>&1 | 
	awk '	BEGIN {state=0}
		/^Node/ {state=1;next;}
		state==1 && NF==0 {exit}
		state==1 && $2 != "UP" {printf("Node \"%s\" is down.\n",$1);}'`

if [ -n "$r" ]
then
	if [ -x "/usr/bin/mailx" ]
	then
		echo "$r" | /usr/bin/mailx -s "Cluster nodes are down" $user
		exit 0
	fi
	if [ -x "/usr/bin/mail" ]
	then
		echo "Subject: Cluster nodes are down\n$r" | 
			/usr/bin/mail $user
	fi
fi

exit 0
